import java.util.*;

public class StackTraceTest {
	/**
	 * A Program that displays a trace feature of a recursive method call
	 * @author PanShanJun
	 */
	public static int factorial(int n) {
		System.out.print("factorial(" + n + "):\n");
		Throwable t = new Throwable();
		StackTraceElement[] frames = t.getStackTrace();
		for (StackTraceElement f : frames)
			System.out.println(f);
		
		int r = 1;
		if (n > 1)
			r = n * factorial(n - 1);
		
		System.out.print("return" + r);
		return r;
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		System.out.print("Enter n: ");
		int n = in.nextInt();
		factorial(n);
	}
}
